package com.xudow.app.ui.adapter;

import android.content.Context;
import android.content.Intent;
import android.graphics.Paint;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.activeshare.edu.ucenter.models.base.OrderItems;
import com.activeshare.edu.ucenter.models.course.CourseWithOtherInfo;
import com.xudow.app.Config;
import com.xudow.app.R;
import com.xudow.app.ui.CourseDetailActivity;
import com.xudow.app.util.ImageUtils;

import java.util.List;

/**
 * 作者：zhouXJ on 2016/5/11 15:45
 */
public class OrderDetialAdapter extends BaseAdapter {
    Context context;
    List<OrderItems> data;
    public OrderDetialAdapter(Context cxt,List<OrderItems> itemses){
        this.context=cxt;
        this.data=itemses;
    }
    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View v, ViewGroup parent) {
        ViewHolder holder;
        if (null==v){

            holder=new ViewHolder();
            v=View.inflate(context, R.layout.item_orderdetial_coures,null);
            holder.coursename=(TextView)v.findViewById(R.id.courceName_tv);
            holder.coursetype=(TextView)v.findViewById(R.id.courceType_tv);
            holder.act_price=(TextView)v.findViewById(R.id.actual_price_tv);
            holder.price=(TextView)v.findViewById(R.id.price_tv);
            holder.studentname=(TextView)v.findViewById(R.id.studentName_tv);
            holder.courseIco=(ImageView)v.findViewById(R.id.cource_img);
            holder.tv1=(TextView)v.findViewById(R.id.tv_1);
            holder.tv2=(TextView)v.findViewById(R.id.tv_2);
            holder.tv3=(TextView)v.findViewById(R.id.tv_3);
            holder.tv4=(TextView)v.findViewById(R.id.tv_4);
            holder.tv5=(TextView)v.findViewById(R.id.tv_5);
            holder.course_layout=(RelativeLayout)v.findViewById(R.id.course_layout);
            v.setTag(holder);
        }else
            holder=(ViewHolder)v.getTag();
        CourseWithOtherInfo course=data.get(position).getCourse();
        holder.coursename.setText(course.getName());
        if (course.getType()==0)
            holder.coursetype.setText("一对一");
        else
            holder.coursetype.setText("辅导班");
        holder.studentname.setText(data.get(position).getStudent().getName());
        holder.act_price.setText(course.getActualPrice() + "0");
        holder.price.setText(course.getCoursePrice()+ "0");
        holder.price.getPaint().setFlags(Paint.STRIKE_THRU_TEXT_FLAG);
        if (null!=data.get(position).getCouponsprice())
            holder.tv1.setText(data.get(position).getCouponsprice() + "");
        if (null!=data.get(position).getDiscount())
             holder.tv2.setText(data.get(position).getDiscount()+"");
        if (null!=data.get(position).getReduceprice())
            holder.tv3.setText(data.get(position).getReduceprice()+"");
        if (null!=data.get(position).getScholarshipprice())
             holder.tv4.setText(data.get(position).getScholarshipprice()+"");
        if (null!=data.get(position).getSpecialprice())
            holder.tv5.setText(data.get(position).getSpecialprice()+"");
        //加载课程图片
        String imageUrl = String.format(Config.IMAGE_LOAD_URL_PARAMS, data.get(position).getCourse().getThumbnail());
        ImageUtils.loadImage(context, holder.courseIco, imageUrl, R.mipmap.def_course_ico);



         holder.course_layout.setOnClickListener(new View.OnClickListener() {
             @Override
             public void onClick(View v) {
                 Intent inten=new Intent(context,CourseDetailActivity.class);
                 inten.putExtra("courseId",data.get(position).getCourseId());
                 context.startActivity(inten);
             }
         });

        return v;
    }

    class ViewHolder{
        TextView coursename,coursetype,act_price,price,studentname,tv1,tv2,tv3,tv4,tv5;
        ImageView courseIco;
        RelativeLayout course_layout;
    }
}
